-
Notifications
You must be signed in to change notification settings - Fork 1k
Turn on wrangler.json(c) support by default
#7230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 174a555 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-wrangler-7230You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7230/npm-package-wrangler-7230Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-wrangler-7230 dev path/to/script.jsAdditional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-create-cloudflare-7230 --no-auto-updatenpm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-cloudflare-kv-asset-handler-7230npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-miniflare-7230npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-cloudflare-pages-shared-7230npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-cloudflare-vitest-pool-workers-7230npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-cloudflare-workers-editor-shared-7230npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-cloudflare-workers-shared-7230npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-cloudflare-workflows-shared-7230Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
aeab1b9 to
61329eb
Compare
petebacondarwin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ran out of time so dumping my comments so far.
| \`\`\` | ||
| \`\`\` | ||
| [[migrations]] | ||
| tag = \\"v1\\" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this change seems a bit out of place for this PR.
| Or you could pass it in your terminal as \`--compatibility-date XXXX-XX-XX\` | ||
| See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information." | ||
| `); | ||
| "A compatibility_date is required when publishing. Add the following to your wrangler.toml file:. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the snippet below is now JSON I think this needs to be wrangler.json.
| - In wrangler.toml, you have configured [durable_objects] exported by this Worker (SomeClass), | ||
| but no [migrations] for them. This may not work as expected until you add a [migrations] section | ||
| to your wrangler.toml. Add this configuration to your wrangler.toml: | ||
| - In wrangler.toml, you have configured [durable_objects] exported by this Worker (SomeClass), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to change these messages to accommodate the actual format of the config file in use?
| export type Config = ConfigFields<DevConfig> & PagesConfigFields & Environment; | ||
| export type Config = ConfigFields<DevConfig> & | ||
| PagesConfigFields & | ||
| Environment & { parsedFormat?: "jsonc" | "toml" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not keen on adding extra stuff inline here.
I note that there is already a precedent in that configPath is part of ConfigFields but is not something we can read from the wrangler.toml/json directly (despite appearing in RawConfig).
I think the most accurate way to do this is to create a new ConfigInfo type, which contains configPath and parsedFormat (perhaps configFormat?).
Then include this in the Config type (and not in the ConfigFields type) wyich will avoid it appearing in the RawConfig type.
| experimentalJsonConfig?: boolean | undefined; | ||
| }; | ||
| export function formatConfigSnippet( | ||
| config: RawEnvironment, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call this something like snippet to avoid the reader from thinking that we are passing in the current Wrangler configuration here?
| export function formatConfigSnippet( | ||
| config: RawEnvironment, | ||
| parsedFormat: Config["parsedFormat"], | ||
| spacing = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BIKESHED: formatted or pretty or something?
petebacondarwin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love where this is going but the more I read through the changes the more I questioned whether we need a parseFormat property on config.
We have the configPath property already, and it would be simple to provide a helper function like:
function configFormat(configPath: string|undefined): "json"|"toml"|"none" { ... }This means not having to thread this extra parameter around alongside the configPath.
Moreover, as you can guess from the signature of the helper function above, there is the scenario where the user has not provided a config file at all, which we need to support. In that case, snippet messaging might be more along the lines of "Create a wrangler.json with this content".
| configPath: string | undefined, | ||
| args: NormalizeAndValidateConfigArgs | ||
| args: NormalizeAndValidateConfigArgs, | ||
| parsedFormat: Config["parsedFormat"] = "toml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is internal, so there is no value in making this field optional, IMO. It is better to constrain all usage to provide this. That also helps to ensure we have considered every usage.
Also since this and configPath are similar properties (in their usage) I would propose to group this new param as the third one ahead of args.
…rangler.json is used
217e8b4 to
5d3a166
Compare
petebacondarwin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it!
There may be some instances missing but I didn't find any.
Ship it!
| ) { | ||
| fs.writeFileSync( | ||
| path, | ||
| formatConfigSnippet( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sneaky!
Co-authored-by: Pete Bacon Darwin <[email protected]>
Fixes DEVX-1466
Turn on the
--experimental-json-configflag by default, enabling reading ofwrangler.json&wrangler.jsoncconfig files. It can still be disabled by setting--experimental-json-config=false. Since it's on by default, this also unblocks support for Pages (pending release of this PR & bumping of Wrangler in the build image)This PR only enables it in Wrangler. Follow up PRs will adjust the documentation to call out this support properly as well as updating C3.